package xjtu.se.articlecommunity.buser.articlemanage.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import xjtu.se.articlecommunity.buser.articlemanage.dto.articleDto;
import xjtu.se.articlecommunity.buser.articlemanage.dto.at_tabDto;

import java.util.List;

public interface ArticleManageDao {

    @Delete("delete from t_article_tab where at_tab=#{at_id}")
    void deleteTab(String at_id);

    List<articleDto> getArticleList(articleDto dto);

    @Select("select count(*) from t_article where a_id=#{a_id}")
    int has_article(String a_id);

    @Select("select count(*) from t_article_tab where at_tab=#{at_id}")
    int has_article_tab(String at_id);

    @Select("select tat.at_tab, tat.at_name," +
            " (select count(*) from art_tab at " +
            "where at.a_id=#{a_id} and at.at_tab=tat.at_tab ) has" +
            " from t_article_tab tat")
    List<at_tabDto> queryTabList(String a_id);

    @Delete("delete from art_tab where a_id=#{a_id}")
    void removeTabForArticle(String a_id);

    @Insert("insert into art_tab (a_id, at_tab) values (#{a_id}, #{tab})")
    void addTabToArticle(String a_id, String tab);

    @Delete("delete from t_feed where a_id=#{a_id}")
    void removeRelatedFeed(String a_id);

    @Update("update t_article set a_status=#{a_status} where a_id=#{a_id}")
    void setArticleStatus(String a_id, int a_status);

    @Delete("delete from t_feed where at_tab=#{at_id}")
    void deleteFeedWithTab(String at_id);

    @Delete("delete from art_tab where at_tab=#{at_id}")
    void deleteRelativeArtTabForID(String at_id);

    @Select("select count(*) from t_article_tab where at_name=#{at_name}")
    int findTabByName(String at_name);

    @Insert("insert into t_article_tab (at_tab, at_name) values (#{at_id}, #{at_name})")
    void newTab(String at_id, String at_name);

    @Select("select * from t_article_tab")
    List<at_tabDto> queryAllTabs();
}
